import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-03-12
 * Time: 16:15
 */
public class Test {
    static void menu() {
        System.out.println("-----------------------");
        System.out.println("1. 增");
        System.out.println("2. 删");
        System.out.println("3. 查");
        System.out.println("4. 改");
        System.out.println("0. 退出");
        System.out.println("-----------------------");
    }
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/javaAssignment?" +
                "characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("密码");
        Connection connection = dataSource.getConnection();
        int input = 0;
        Scanner scanner = new Scanner(System.in);
        Opera[] operas = {new Exit(), new Add(), new Del(), new Search(), new Update()};
        do {
            menu();
            input = scanner.nextInt();
            if(input <= 4 && input >= 0) {
                operas[input].opera(connection);
            }else {
                System.out.println("输入错误~");
            }
        }while(input != 0);
        connection.close();
    //虽然程序结束自动关闭，但是大一点的程序，这样的坏习惯可能会害了你
    }
}
